<?php

/**
 * Framework_Module
 *
 * @author Application Support Group
 * @copyright University of Georgia
 * @package BAMF
 * @filesource
*/

/**
 * Framework_Module
 * 
 * The base module class. All applications will extends from this class. This
 * means each module will, by default, have an open DB connection and an
 * open log file to write to. Also, it's a good place to put functions, 
 * variables, etc. that all modules need.
 *
 * @author Application Support Group
 * @package BAMF
*/
abstract class Framework_Module extends Framework_Object {

    /**
     * $uuid
     *
     * This is the unique identifier for this instance of the module.
     *
     * @author Application Support Group
     * @var mixed $user Instnace of Framework_User of current user
    */
	public $uuid ;


    /**
     * $loggedInUser
     *
     * This is the current user. If the user is not logged in then the
     * information defaults to the special anonymous user (user_id = 0).
     *
     * @author Application Support Group
     * @var mixed $user Instnace of Framework_User of current user
    */
	protected $loggedInUser;

    /**
     * $session
     *
     * A simple wrapper class around PHP's $_SESSION variable.
     *
     * @author Application Support Group
     * @var mixed $session Instance of Framework_Session
    */
	protected $session;

    /**
    /**
     * $presenter
     *
     * Used in Framework_Presenter::factory() to determine which presentation 
     * (view) class should be used for the module.
     *
     * @author Application Support Group
     * @var string $presenter 
     * @see Framework_Presenter, Framework_Presenter_Common
     * @see Framework_Presenter_Smarty
    */
	public $presenter = null ;

    /**
     * $data
     *
     * Data set by the module that will eventually be passed to the view.
     *
     * @author Application Support Group
     * @var mixed $data Module data
     * @see Framework_Module::set(), Framework_Module::getData()
    */
	protected $data = array();

    /**
     * $name
     *
     * @author Application Support Group
     * @var string $name Name of module class
    */
	public $name;

    /**
     * $tplFile
     *
     * @author Application Support Group
     * @var string $tplFile Name of template file
     * @see Framework_Presenter_Smarty
    */
	public $tplFile;

    /**
     * $moduleName
     *
     * @author Application Support Group
     * @var string $moduleName Name of requested module
     * @see Framework_Presenter_Smarty
    */
	public $moduleName = null;

    /**
     * $pageTemplateFile
     *
     * @author Application Support Group
     * @var string $pageTemplateFile Name of outer page template
    */
	public $pageTemplateFile = null;
	
    /**
     * $i18n
     *
     * @author Application Support Group
     * @var mixed $i18n I18n object for internationalization
     * @see Framework_Util_I18n
    */
	public $i18n = null;
	

    /**
     * __construct
     * 
     * @author Application Support Group
     * @access public
     * @return void
    */
	public function __construct() {
		parent::__construct();
		$this->presenter = !empty( $_SESSION['active_presenter'] ) ? $_SESSION['active_presenter'] : FRAMEWORK_DEFAULT_PRESENTER ;
		$this->name = $this->me->getName();
		$parts = explode('_',$this->name);
		$this->moduleName = array_pop($parts) ;
		$this->session = Framework_Session::singleton() ;
		$this->loggedInUser = new Framework_LoggedInUser( $this->session->idField, $this->session->idValue );
		$this->uuid = Framework_Util_Uuid::get() ;
		$this->i18n = new Framework_Util_I18n() ;
	}



    /**
     * authenticated
     *
     * This function is run by the controller to see if the module's
     * doAction() method should be executed.
     *
     * @author Application Support Group
     * @access public
     * @return mixed
    */
	abstract public function authenticated( $authUserField );




    /**
     * doAction
     *
     * This function is run by the controller and is the main body of procedural
     * logic for any given "ActionClass".
     *
     * @author Application Support Group
     * @access public
     * @return mixed
    */
	abstract public function doAction();




    /**
     * set
     *
     * Set data for your module. This will eventually be passed to the
     * presenter class via Framework_Module::getData().
     *
     * @author Application Support Group
     * @param string $var Name of variable
     * @param mixed $val Value of variable
     * @return void
     * @see Framework_Module::getData()
    */
	protected function set($var,$val) {
		$this->data[$var] = $val; 
	}

    /**
     * getData
     *
     * Returns module's data. 
     *
     * @author Application Support Group
     * @return mixed
     * @see Framework_Presenter_Common
    */
	public function getData() {
		return $this->data;
	}

    /**
     * isValid
     *
     * Determines if $module is a valid framework module. This is used by
     * the controller to determine if the module fits into our framework's
     * mold. If it extends from both Framework_Module and Framework_Auth then 
     * it should be good to run.
     *
     * @author Application Support Group
     * @static
     * @param mixed $module
     * @return bool
    */
	public static function isValid($module) {
		return( is_object( $module ) && $module instanceof Framework_Module );
	}

    /**
     * __destruct
     *
     * @author Application Support Group
     * @access public
     * @return void
    */
	public function __destruct() {
		parent::__destruct();
	}
}

?>
